package com.mills.gamebase.service;

import org.apache.log4j.Logger;
import org.springframework.web.context.WebApplicationContext;

/**
 * Diese Klasse dient der Haltung des WebApplicationContext
 * 
 * @author mills
 *
 */
public class WebApplicationContextHolder {
	
	private static Logger logger = Logger.getLogger(WebApplicationContextHolder.class);

	private static WebApplicationContextHolder webApplicationContextHolder;
	private WebApplicationContext webApplicationContext;
	
	public static WebApplicationContextHolder getInstance() {
		
		if (webApplicationContextHolder == null) {
			if (logger.isDebugEnabled()) {
				logger.debug("Initiating WebApplicationContextHolder...");
			}
			
			webApplicationContextHolder = new WebApplicationContextHolder();
		}
		
		return webApplicationContextHolder;
	}
	
	public boolean isSet() {
		return this.webApplicationContext != null;
	}
	
	public WebApplicationContext getWebApplicationContext() {
		return webApplicationContext;
	}
	
	public void setWebApplicationContext(WebApplicationContext webApplicationContext) {
		if (logger.isDebugEnabled()) {
			logger.debug("Setting WebApplicationContext...");
		}
		
		this.webApplicationContext = webApplicationContext;
	}
}
